package routes

import (
	index_v1 "lingc/controllers/index/v1"
	manage "lingc/controllers/manage"
	"lingc/middlewares"

	"github.com/gin-gonic/gin"
)

// SetupRouter 设置路由
func SetupRouter() *gin.Engine {
	r := gin.Default()

	wsGroup := r.Group("/api/ws")
	{
		// websocket
		wsGroup.GET("/socket", index_v1.WebSocketHandler)
	}
	admin := r.Group("/api/manage", middlewares.LangMiddleware()) // 添加中间件
	{
		// 图形验证码
		admin.GET("/auth/captcha", manage.GenerateCaptcha)
		// 登录
		admin.POST("/auth/login", manage.AuthLogin)
		// 获取语言翻译列表
		admin.GET("/config/lang", manage.GetLangList)
		// 获取系统配置
		admin.GET("/config/data", manage.GetSysConfigData)
		// 上传图片
		admin.POST("/files/upload", manage.UploadImage)
		// 设置语言条目
		admin.GET("/setlang/text", manage.SetLangText)
		// 刷新语言翻译
		admin.GET("/config/googletrans", manage.UpdateSysLangList)

	}
	admin_auth := r.Group("/api/manage", middlewares.AuthMiddleware(), middlewares.LangMiddleware()) // 添加中间件
	{
		//获取聊天组
		admin_auth.GET("/chatGroup/page", manage.GetChatGroup)
		//获取聊天记录
		admin_auth.GET("/chatHistory/page", manage.GetChatHistoryList)
		//创建菜单
		admin_auth.GET("/auth/create/menu", manage.CreateMenu)
		// 用户信息
		admin_auth.GET("/users/info", manage.GetUsersInfo)
		// 刷新token
		admin.POST("/auth/refreshtoken", manage.AuthRefreshtoken)
		// 退出登录
		admin_auth.GET("/auth/logout", manage.AuthLogout)
		// 删除图片
		admin_auth.POST("/files/delete", manage.DeleteImage)
		// 管理员路由
		admin_auth.GET("/authUser/page", manage.PageAuthUser)
		admin_auth.GET("/authUser/info", manage.GetAuthUser)
		admin_auth.POST("/authUser/create", manage.CreateAuthUser)
		admin_auth.POST("/authUser/update", manage.UpdateAuthUser)
		admin_auth.POST("/authUser/delete", manage.DeleteAuthUser)

		// 权限组路由
		admin_auth.GET("/authGroup/page", manage.PageAuthGroup)
		admin_auth.GET("/authGroup/info", manage.GetAuthGroup)
		admin_auth.POST("/authGroup/create", manage.CreateAuthGroup)
		admin_auth.POST("/authGroup/update", manage.UpdateAuthGroup)
		admin_auth.POST("/authGroup/delete", manage.DeleteAuthGroup)

		// 菜单路由
		admin_auth.GET("/authRule/page", manage.PageAuthRule)
		admin_auth.GET("/authRule/info", manage.GetAuthRule)
		admin_auth.POST("/authRule/create", manage.CreateAuthRule)
		admin_auth.POST("/authRule/update", manage.UpdateAuthRule)
		admin_auth.POST("/authRule/delete", manage.DeleteAuthRule)

		// 操作日志
		admin_auth.GET("/authHandleLog/page", manage.PageAuthHandleLog)
		admin_auth.GET("/authHandleLog/info", manage.GetAuthHandleLog)
		admin_auth.POST("/authHandleLog/create", manage.CreateAuthHandleLog)
		admin_auth.POST("/authHandleLog/update", manage.UpdateAuthHandleLog)
		admin_auth.POST("/authHandleLog/delete", manage.DeleteAuthHandleLog)

		// 系统配置
		admin_auth.GET("/sysConfig/page", manage.PageSysConfig)
		admin_auth.GET("/sysConfig/info", manage.GetSysConfig)
		admin_auth.POST("/sysConfig/create", manage.CreateSysConfig)
		admin_auth.POST("/sysConfig/update", manage.UpdateSysConfig)
		admin_auth.POST("/sysConfig/delete", manage.DeleteSysConfig)

		// 系统文章
		admin_auth.GET("/sysContent/page", manage.PageSysContent)
		admin_auth.GET("/sysContent/info", manage.GetSysContent)
		admin_auth.POST("/sysContent/create", manage.CreateSysContent)
		admin_auth.POST("/sysContent/update", manage.UpdateSysContent)
		admin_auth.POST("/sysContent/delete", manage.DeleteSysContent)

		// 系统banner
		admin_auth.GET("/sysBanner/page", manage.PageSysBanner)
		admin_auth.GET("/sysBanner/info", manage.GetSysBanner)
		admin_auth.POST("/sysBanner/create", manage.CreateSysBanner)
		admin_auth.POST("/sysBanner/update", manage.UpdateSysBanner)
		admin_auth.POST("/sysBanner/delete", manage.DeleteSysBanner)

		// 语言管理
		admin_auth.GET("/sysLang/page", manage.PageSysLang)
		admin_auth.GET("/sysLang/info", manage.GetSysLang)
		admin_auth.POST("/sysLang/create", manage.CreateSysLang)
		admin_auth.POST("/sysLang/update", manage.UpdateSysLang)
		admin_auth.POST("/sysLang/delete", manage.DeleteSysLang)

		// 语言条目
		admin_auth.GET("/sysLangItem/page", manage.PageSysLangItem)
		admin_auth.GET("/sysLangItem/info", manage.GetSysLangItem)
		admin_auth.POST("/sysLangItem/create", manage.CreateSysLangItem)
		admin_auth.POST("/sysLangItem/update", manage.UpdateSysLangItem)
		admin_auth.POST("/sysLangItem/delete", manage.DeleteSysLangItem)

		// 会员管理
		admin_auth.GET("/member/page", manage.PageMember)
		admin_auth.GET("/member/info", manage.GetMember)
		admin_auth.POST("/member/create", manage.CreateMember)
		admin_auth.POST("/member/update", manage.UpdateMember)
		admin_auth.POST("/member/delete", manage.DeleteMember)

		// 会员等级管理
		admin_auth.GET("/memberLevel/page", manage.PageMemberLevel)
		admin_auth.GET("/memberLevel/info", manage.GetMemberLevel)
		admin_auth.POST("/memberLevel/create", manage.CreateMemberLevel)
		admin_auth.POST("/memberLevel/update", manage.UpdateMemberLevel)
		admin_auth.POST("/memberLevel/delete", manage.DeleteMemberLevel)

		// 消息自动回复
		admin_auth.GET("/autoReply/page", manage.PageChatAutoReply)
		admin_auth.GET("/autoReply/info", manage.GetChatAutoReply)
		admin_auth.POST("/autoReply/create", manage.CreateChatAutoReply)
		admin_auth.POST("/autoReply/update", manage.UpdateChatAutoReply)
		admin_auth.POST("/autoReply/delete", manage.DeleteChatAutoReply)

	}

	member_v1 := r.Group("/api/index/v1", middlewares.LangMiddleware()) // 添加中间件
	{
		// 图形验证码
		member_v1.GET("/member/captcha", index_v1.GenerateCaptcha)
		// 用户登录
		member_v1.POST("/member/login", index_v1.MemberLogin)
		// 获取语言翻译列表
		member_v1.GET("/config/lang", index_v1.GetLangList)
		// 获取系统配置
		member_v1.GET("/config/data", index_v1.GetSysConfigData)
	}

	member_token_v1 := r.Group("/api/index/v1", middlewares.MemberMiddleware(), middlewares.LangMiddleware())
	{
		//获取聊天记录
		member_token_v1.GET("/chatHistory/page", index_v1.GetChatHistoryList)
		// 用户信息
		member_token_v1.GET("/member/info", index_v1.GetMemberInfo)
		// 退出登录
		member_token_v1.GET("/member/logout", index_v1.MemberLogout)
		// 刷新token
		member_token_v1.POST("/member/refreshtoken", index_v1.MemberRefreshtoken)
		// 上传图片
		member_token_v1.POST("/files/upload", index_v1.UploadImage)
		// 删除图片
		member_token_v1.POST("/files/delete", index_v1.DeleteImage)

	}

	return r
}
